home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
SYSTEM
/
HISTORY.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1997-06-04
|
3KB
|
121 lines
unit History;
interface
uses SysUtils, Classes, WinProcs, IniFiles;
function GetHistoryList (const ListName: String): TStringList;
procedure AddHistoryString (const ListName, Str: String);
implementation
uses Delimit;
const
MaxStrings = 10;
var
HLists: TStringList;
function GetHistoryList (const ListName: String): TStringList;
var
Idx: Integer;
begin
Idx := HLists.IndexOf (ListName);
if Idx = -1 then Idx := HLists.AddObject (ListName, TStringList.Create);
Result := TStringList (HLists.Objects [Idx]);
end;
procedure AddHistoryString (const ListName, Str: String);
var
Idx: Integer;
List: TStringList;
begin
List := GetHistoryList (ListName);
Idx := List.IndexOf (Str);
if Idx <> -1 then List.Delete (Idx) else
if List.Count = MaxStrings then List.Delete (MaxStrings - 1);
List.Insert (0, Str);
end;
procedure HistoryShutdown; far;
var
Str: String;
List: TStringList;
IniFile: TIniFile;
Idx, Num: Integer;
begin
IniFile := TIniFile.Create (ChangeFileExt (ParamStr (0), '.INI'));
try
IniFile.EraseSection ('History');
for Idx := 0 to HLists.Count - 1 do begin
List := TStringList (HLists.Objects [Idx]);
if List.Count > 0 then begin
Str := '';
for Num := 0 to List.Count - 1 do begin
Str := Str + List.Strings [Num];
if Num < List.Count - 1 then Str := Str + ',';
end;
IniFile.WriteString ('History', HLists.Strings [Idx], Str);
end;
List.Free;
end;
HLists.Free;
finally
IniFile.Free;
end;
end;
procedure HistoryStartup;
var
Idx: Integer;
IniFile: TIniFile;
NamesList: TStringList;
procedure AddList (const ListName: String);
var
Idx: Integer;
NewList: TStringList;
ds: TDelimitedString;
begin
ds := TDelimitedString.CreateAssign (IniFile.ReadString ('History', ListName, ''));
try
if ds.FieldCount > 0 then begin
NewList := TStringList.Create;
for Idx := 0 to ds.FieldCount - 1 do
NewList.Add (ds [Idx]);
HLists.AddObject (ListName, NewList);
end;
finally
ds.Free;
end;
end;
begin
HLists := TStringList.Create;
IniFile := TIniFile.Create (ChangeFileExt (ParamStr (0), '.INI'));
try
NamesList := TStringList.Create;
try
IniFile.ReadSection ('History', NamesList);
for Idx := 0 to NamesList.Count - 1 do
AddList (NamesList.Strings [Idx]);
finally
NamesList.Free;
end;
finally
IniFile.Free;
end;
end;
initialization
HistoryStartup;
{$IFDEF WIN32}
finalization
HistoryShutdown;
{$ELSE}
AddExitProc (HistoryShutdown);
{$ENDIF}
end.